//
//  DDBaseViewController.m
//  ialone
//
//  Created by lanou on 16/1/12.
//  Copyright © 2016年 JasperSong. All rights reserved.
//

#import "DDBaseViewController.h"
#import "SCGIFImageView.h"

@interface DDBaseViewController ()

@property (nonatomic, strong) SCGIFImageView *gifImageView;

@end

@implementation DDBaseViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    // 显示边缘手势
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
}
// 懒加载
- (UIView *)topView{
    if (!_topView) {
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, kScreenWidth, 44)];
        _topView.backgroundColor = kBaseColor;
        [self.view addSubview:_topView];
        self.stateView.backgroundColor = kBaseColor;
    }
    return _topView;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        // 标题的label
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth/2) - 75, 5, 150, 34)];
        _titleLabel.adjustsFontSizeToFitWidth = YES;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor whiteColor];
        [self.topView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UIView *)stateView{
    if (!_stateView){
        _stateView = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 20)];
        _stateView.backgroundColor = kBaseColor;
        [self.view addSubview:_stateView];
    }
    return _stateView;
}

- (UIButton *)leftButton{
    if (!_leftButton){
        _leftButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _leftButton.frame = CGRectMake(kSMarge, kSMarge + 20, self.topView.height - kLMarge, self.topView.height - kLMarge);
        [self.view addSubview:_leftButton];
        [self.view bringSubviewToFront:_leftButton];
    }
    
    return _leftButton;
}


// 分享
- (UIButton *)share{
    if (!_share) {
        _share = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _share.frame = CGRectMake(kScreenWidth - (self.topView.height - kLMarge) - 20, kSMarge + 20, self.topView.height - kLMarge, self.topView.height - kLMarge);
        [self.view addSubview:_share];
        [self.view bringSubviewToFront:_share];
    }
    return _share;
}


// 收藏
- (UIButton *)collection{
    if (!_collection) {
        _collection = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _collection.frame = CGRectMake(kScreenWidth - (self.topView.height - kLMarge) - 20 - (self.topView.height - kLMarge) - 20, kSMarge + 20,self.topView.height - kLMarge , self.topView.height - kLMarge);
        [self.view addSubview:_collection];
        [self.view bringSubviewToFront:_collection];
    }
    return _collection;
}

//注册
-(UIButton *)registerbutton{
    if (!_registerbutton) {
        _registerbutton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _registerbutton.frame = CGRectMake(kScreenWidth - (self.topView.height - kLMarge) - 20, kSMarge * 5, self.topView.height , self.topView.height - kLMarge);
        
        [self.view addSubview:_registerbutton];
        [self.view bringSubviewToFront:_registerbutton];
    }
    return _registerbutton;
}



- (void)hubShow{
    [self p_setupProgressHud];
}

- (void)hubHide{
    [_hud hide:YES];
}

- (void)p_setupProgressHud
{
    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
    
//    // 更改指示器的样式
//    
//    NSString* filePath = [[NSBundle mainBundle] pathForResource:@"load.gif" ofType:nil];
//    NSData* imageData = [NSData dataWithContentsOfFile:filePath];
//    
//    _gifImageView = [[SCGIFImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
////    _gifImageView.center = CGPointMake(kScreenWidth/2, kScreenHeight/2);
//    [_gifImageView setData:imageData];
//
//    
//    self.hud.customView = [[UIImageView alloc] initWithImage:_gifImageView.image];
    
    _hud.frame = self.view.bounds;
    _hud.minSize = CGSizeMake(100, 100);
    _hud.mode = MBProgressHUDModeIndeterminate;
    [self.view addSubview:_hud];
    [_hud show:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    _leftButton = nil;
    _titleLabel = nil;
    _leftButton = nil;
    _topView = nil;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}


// 状态栏前景色的模式
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
